/**
 * 读取 resource/1.html  2.html  3.html  合并输出结果
 */
const fs = require('fs');
const util = require('util');

//回调地狱形式
// fs.readFile('./resource/1.html', (err, data1) => {
//     fs.readFile('./resource/2.html', (err, data2) => {
//         fs.readFile('./resource/3.html', (err, data3) => {
//             //拼接
//             console.log(data1.toString() + data2.toString() + data3.toString());
//         });
//     });
// });

//Promise.all
//创建返回 promise 风格的函数
let mineReadFile = util.promisify(fs.readFile);

let p1 = mineReadFile('./resource/1.html');
let p2 = mineReadFile('./resource/2.html');
let p3 = mineReadFile('./resource/3.html');

let result = Promise.all([p1, p2, p3]);

result.then(v => {
    // console.log(v);
    console.log(v.map(item => item.toString()).join(''));
}, r => {
    console.log(r);
})









